﻿'This file is part of WSUS Helper <http://wsushelper.codeplex.com/>.

'WSUS Helper is free software: you can redistribute it and/or modify
'it under the terms of the GNU General Public License as published by
'the Free Software Foundation, either version 2 of the License, or
'(at your option) any later version.

'WSUS Helper is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'GNU General Public License for more details.

'You should have received a copy of the GNU General Public License
'along with WSUS Helper.  If not, see <http://www.gnu.org/licenses/>.

Public Class GroupPicker

    Public SelectedGroup As IComputerTargetGroup

    Private Sub GroupPicker_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

        lbGroups.Items.Clear()
        lbGroups.ValueMember = "Name"

        For Each oItem As IComputerTargetGroup In Main.cbViewGroup.Items
            lbGroups.Items.Add(oItem)
        Next

        'Focus the list so scrolling works without the user having to click first.
        lbGroups.Focus()

    End Sub

    Private Sub lbGroups_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbGroups.SelectedIndexChanged
        'Only enable button if a group is selected.
        btnOK.Enabled = Not (lbGroups.SelectedIndex = -1)
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        'Store the selected group and close the form.
        SelectedGroup = lbGroups.SelectedItem
        Me.Close()
    End Sub
End Class